#ifndef VERTEXBUFFEROBJECT_H
#define VERTEXBUFFEROBJECT_H

#include "vecmath.h"
#include <QtOpenGL>
#include "vertexarray.h"

class VertexBufferObject
{
public:
    VertexBufferObject(VertexArray* vertexArray, bool ownerVertexArray = true);
    ~VertexBufferObject();
    
    VertexArray* getVertexArray() const { return vertexArray; }
    void setVertexArray(VertexArray* vertexArray);
    
    void generate();
    void send(bool deleteVertexArray = true);
    void setPointers();
    void bind();
    
    static void enableClientStates();
    static void disableClientStates();
    static void unbindBuffers();
    
    void draw(GLenum mode);
    void draw(GLenum mode, unsigned location);
    void draw(GLenum mode, unsigned location, unsigned length);
    
    void oneShotDraw(GLenum mode);
    void oneShotDraw(GLenum mode, unsigned location);
    void oneShotDraw(GLenum mode, unsigned location, unsigned length);
    
private:
    VertexArray* vertexArray;
    bool ownerVertexArray;
    GLuint bufferIds[2];
    
    unsigned verticesSize;
    unsigned indicesSize;
};

#endif // VERTEXBUFFEROBJECT_H
